<template>
  <div>
    <query-table ref="modelTargetRefQueryTable" :page-size="10" :columns="columns" :query-fields="queryFields"
                 :detail-fields="modelTargetRefFields"
                 :append-buttons="appendButtons" base-url="/settings/model/target_ref"></query-table>

  </div>
</template>
<script>
export default {
  name: "ModelTargetRefList",
  data() {
    return {
      detailDlgVisible: false,
      modelTargetRef: {},
      loadingModelTargetRef: false,
      //表格列
      columns: [
        {id: 'modelId', name: '模型id',type:'name-display',dataUrl:'/model/data'},
        {id: 'targetType', name: '目标类型',type:'meta',source:'model-target-type',},
        {id: 'targetId', name: '目标',type:'office'},
        {
          id: 'operation', name: '操作', type: 'button', children: [
            // {text: '编辑', click: this.openEditDlg},
            {type: 'danger', text: '删除', operation: 'delete'},
          ]
        },
      ],
      //查询字段
      queryFields: [
        {id: 'modelId', name: '评价模型',component:{id:'data-select',dataUrl:'/model/data'}, colSpan: 6},
        {id: 'targetType', name: '目标类型',component:{id:'meta-select',type:'model-target-type'}, colSpan: 6},
        // {id: 'targetId', name: '目标id', colSpan: 6},
      ],
      //对话框信息字段
      modelTargetRefFields: [
        {id: 'modelId', name: '评价模型',component:{id:'data-select',dataUrl:'/model/data'}, colSpan: 24},
        {id: 'targetType', name: '目标类型',component:{id:'meta-select',type:'model-target-type'}
          ,defaultValue:'office',disabled:true, colSpan: 24},
        {id: 'targetId', name: '目标', component:{id:'company-select'}, colSpan: 24},
      ],
      //查询区域附加按钮
      appendButtons: [
        {text: '新增', type: 'success', operation:'create'},
      ],
    }
  },
  computed: {},
  created() {
  },
  watch: {},
  methods: {

    openEditDlg(item) {
      this.detailDlgVisible = true;
      this.loadingModelTargetRef = true;
      this.$get("/model_target_ref/info/" + item.id, {}, (response) => {
        var modelTargetRefData = response.data;
        this.modelTargetRef = modelTargetRefData;
        this.modelTargetRef.editMode = true;
      }, () => {
        this.loadingModelTargetRef = false;
      });

      // this.modelTargetRef = JSON.parse(JSON.stringify(item));

    },
    openCreateDlg() {
      this.detailDlgVisible = true;
      this.modelTargetRef = {}
    },
    save(id) {
      const message = this.$message;
      if (this.modelTargetRef.editMode) {
        this.$post("/model_target_ref/update", this.modelTargetRef, (response) => {
          this.detailDlgVisible = false;
          message.success('更新成功！');
          this.$refs['$!{tool.firstLowerCase($tableInfo.name)}QueryTable'].reload();
        });
      } else {
        this.$post("/model_target_ref/create", this.modelTargetRef, (response) => {
          this.detailDlgVisible = false;
          message.success('创建成功！');
          this.$refs['$!{tool.firstLowerCase($tableInfo.name)}QueryTable'].reload();

        });
      }
    },

  },

}
</script>

